<?php
include "../include/global.php";
include "../include/admin_check.php";
$xtpl = new XTemplate ("travelstyleWrite.htm");
include "setting.php";
//
include "../include/function.php";
$xtpl->assign("left_panel", left_panel());
$xtpl->assign("header_panel", header_panel());
$xtpl->assign("footer_panel", footer_panel());

// ++ lang
if($lang=='v'){
	$xtpl->assign('type_vietnamese', 'onkeyup="initTyper(this)"');
}
$xtpl->assign("title", TravelStyle);
$xtpl->assign("lbl_search", Search);
$xtpl->assign("lbl_no", No);
$xtpl->assign("lbl_name", Name);
$xtpl->assign("lbl_brief", Brief);
$xtpl->assign("lbl_country", Country);
$xtpl->assign("lbl_position", Position);
$xtpl->assign("lbl_active", Active);
$xtpl->assign("lbl_save", Save);
$xtpl->assign("lbl_save_add", SaveAdd);
$xtpl->assign("lbl_cancel", Cancel);
// -- lang

$ID=intval($_GET['ID']);
if($ID){
	$sql="select * from ".pre_table."travelstyle where travelstyle_id='$ID'";
	$row=recordset($sql);
	$travelstyle_name=$row['travelstyle_name'];	
	$travelstyle_brief=$row['travelstyle_brief'];	
	$travelstyle_position=$row['travelstyle_position'];	
	$travelstyle_isactive=$row['travelstyle_isactive'];	
	
	if($row[travelstyle_isactive]==1) $ChkActive = "checked";			
	
	$xtpl->assign("travelstyle_name", $travelstyle_name);
	$xtpl->assign("travelstyle_brief", $travelstyle_brief);
	$xtpl->assign("travelstyle_position", $travelstyle_position);
	$xtpl->assign("travelstyle_isactive", $travelstyle_isactive);
	$xtpl->assign("ChkActive", $ChkActive);
	$xtpl->assign("id", $ID);
	
	$sql_tree="SELECT country_id FROM ".pre_table."country_travelstyle WHERE travelstyle_id='$ID'";
	$rs_tree=execSQL($sql_tree);
	$arr_tree=array();
	while($row_tree=mysql_fetch_array($rs_tree)){
		$arr_tree[] = $row_tree['country_id'];
	}
	
	$xtpl->assign("type", "EDIT");	
}else{
	// ++ set position
	$stsql = "SELECT travelstyle_id from ".pre_table."travelstyle WHERE lang='".$lang."'";
	$rssql = execSQL($stsql);
	$numrec=mysql_num_rows($rssql);
	$travelstyle_position=$numrec+1;
	$xtpl->assign("travelstyle_position", $travelstyle_position);
	// -- set position
	
	$xtpl->assign("type", "ADD");	
	$xtpl->assign("ChkActive", "checked");
}

// ++ combo country
$sql_country="SELECT country_id, country_name FROM ".pre_table."country 
				WHERE lang='".$lang."'";
$rs_country=execSQL($sql_country);
$cbo_country.="<select class=field name='country_id[]' multiple>";
$cbo_country.='<option value="">---</option>';
while ($rows = mysql_fetch_array($rs_country)){
	$cbo_country.= '<option value="'.$rows['country_id'].'">'.$space.$rows['country_name'].'</option>';
}
$cbo_country.="</select>&nbsp;";
for($i=0; $i < sizeof($arr_tree); $i++){
	$cbo_country =str_replace("value=\"".$arr_tree[$i]."\"","value=\"".$arr_tree[$i]."\" selected",$cbo_country);
}
$xtpl->assign("cbo_country", $cbo_country);
// -- combo country

//////////////////////////////////////
$xtpl->parse("MAIN");
eval("?".">".$xtpl->text("MAIN"));
?>